-- Mousepull

function love.load()
  
  rect = {
    x = 100,
    y = 100,
    width = 100,
    height = 100,
    move = { active = false, diffX = 0, diffY = 0 }
  }
end

function love.update(dt)
  if rect.move.active then
  --love.graphics.print('Clicky!', 400, 200)
    --rect.x = love.mouse.getX() - rect.move.diffX
    --rect.y = love.mouse.getY() - rect.move.diffY
	rect.x = rect.move.diffX
	rect.y = rect.move.diffY
  end
end

function love.draw()
--love.graphics.print('Hello World!', 400, 300)
local e, f = love.mouse.getPosition()
--love.graphics.print("The mouse is at (" .. e .. "," .. f .. ")", 50, 50)
love.graphics.print("The box is at (" .. rect.x .. "," .. rect.y .. ")", 100, 100)
  love.graphics.rectangle("fill", rect.x, rect.y, rect.width, rect.height)
end

function love.mousepressed(x, y, button)
  if button == "l" -- if left button is pressed
  --and x > rect.x and x < rect.x + rect.width
  --and y > rect.y and y < rect.y + rect.height
  and
  x < rect.x or x > rect.x + rect.width
  or y < rect.y or y > rect.y + rect.height
  then
    rect.move.active = true
    rect.move.diffX = x
    rect.move.diffY = y
	--rect.x = love.mouse.getX()
    --rect.y = love.mouse.getY()
  end
  
end

function love.mousereleased(x, y, button)
  if button == "l" then rect.move.active = false end
end